package com.demo.ribbon.sample.service;

import com.demo.ribbon.sample.domain.Hello;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "addFallback")
    public Hello add(String name, Integer age) {
        String url = "http://ribbon-server:9602/hello/add?name=" + name + "&age=" + age;
        System.out.println("request:"+url);
        return restTemplate.getForEntity(url, Hello.class).getBody();
    }


    public Hello addFallback(String name, Integer age) {
        System.out.println("request:add call");
        return new Hello(name, age);
    }


}
